package com.bci.pwtz.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bci.pwtz.mysql.model.Dictionary;
import com.bci.pwtz.service.DictionaryService;
@Controller
@RequestMapping("/user/dictionary")
public class DictionaryController extends AbstractController
{
@Autowired
DictionaryService service;

@RequestMapping(value="/list",method=RequestMethod.POST)
@ResponseBody
public List<Dictionary> getModels(Long typeId){
    List<Dictionary> list=null;
    try{
        list=service.selectDictionary(typeId,getUserId());
    }catch(Exception e){
        e.printStackTrace();
    }
    return list;
}

@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Map<String,String> add(String dictionaryValue,long typeId){
    Map<String, String> map = new HashMap<String, String>();
    try{
        Dictionary dictionary=new Dictionary();
        dictionary.setDictionaryTypeId(typeId);
        dictionary.setDictionaryValue(dictionaryValue);
        dictionary.setRank(0l);
        dictionary.setStatus(2);
        dictionary.setCreatorId(getUserId());
        int ret=service.add(dictionary);
        if(ret>0){
            map = packageAjaxReturnMap(ERROR_VALUE_OP_RESULT_SUCCESS, ERROR_VALUE_MSG_TYPE_INFO, null, "添加数据字典成功");
        }else if(ret ==-1){
            map = packageAjaxReturnMap(ERROR_VALUE_OP_RESULT_FAIL, ERROR_VALUE_MSG_TYPE_ERROR, null, "添加数据字典失败,字典已存在！");
        }else{
            map = packageAjaxReturnMap(ERROR_VALUE_OP_RESULT_FAIL, ERROR_VALUE_MSG_TYPE_ERROR, null, "添加数据字典失败");
        }
        
    }catch(Exception e){
        e.printStackTrace();
    }
    return map;
}
}
